package edu.predatorwars.server.host;

import java.util.ArrayList;
import java.util.Date;
import java.util.UUID;
import edu.predatorwars.server.engine.GameEngine;
import edu.predatorwars.server.engine.GameListener;
import edu.predatorwars.shared.models.Board;
import edu.predatorwars.shared.models.Player;


public class GameInstance implements GameListener {

	private ArrayList<Player> playerList;
	private GameHost host;
	private UUID gameId; 
	private GameEngine engine;
	
	public GameInstance(ArrayList<Player> playerList, GameHost host, UUID gameId, GameEngine engine) {
		this.playerList = playerList; //This is by reference, may need to change
		this.host = host; //Needs reference to host in order to update it
		this.gameId = gameId; //unique identifier for the game
		this.engine = engine;
	}

	public UUID getUUID() {
		return gameId;
	}
	
	public ArrayList<Player> getPlayerList() {
		return playerList;
	}

	@Override
	public void boardChanged(GameEngine engine, Board board) {
		//create message payload, redirect to host
		BoardPayload payload = new BoardPayload(board, playerList, engine.getCurrentPlayer());
		host.latestUpdate(payload);
	}
	
	@Override
	public void gameStateChanged(GameEngine engine, int boardState) {
		//create message payload, redirect to host
		if (boardState == 1) {
			//character selection stage, different payload type
			CharacterListPayload payload = new CharacterListPayload(engine.getAvailableCreatures());
			host.latestUpdate(payload, playerList);
		} else {
			StateChangePayload payload = new StateChangePayload(boardState, engine.getPlayers());
			host.latestUpdate(payload);
		}
	}



}
